import defaultSettings from '@/settings'

const { showSettings, fixedHeader, sidebarLogo } = defaultSettings

const state = {
  showSettings: showSettings,
  fixedHeader: fixedHeader,
  sidebarLogo: sidebarLogo
}

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    // eslint-disable-next-line no-prototype-builtins
    if (state.hasOwnProperty(key)) {
      state[key] = value
    }
  },
  // 1. mutation 接收一个参数 fixed，表示是否显示固定的头部
  setFixedHeader: (state, fixed) => {
    state.fixedHeader = fixed
  }
}

const actions = {
  changeSetting({ commit }, data) {
    commit('CHANGE_SETTING', data)
  },
  // 2. actions 中添加相应的方法，以便调用这个 mutation
  setFixedHeader({ commit }, fixed) {
    commit('setFixedHeader', fixed)
  }
  // 3. store.dispatch('settings/setFixedHeader', false)
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

